package threadcoreknowledge.threadobjectclasscommonmethods.join;

import java.util.concurrent.TimeUnit;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Task liyuan = new Task();
        Task lishiming = new Task();
        Task liyuanba = new Task();

        liyuanba.setName("李元霸");
        lishiming.setName("李世民");
        liyuan.setName("李渊");

        Thread[] threads = new Thread[3];
        threads[0]=lishiming;
        threads[1]=liyuanba;
        threads[2]=Thread.currentThread();
        liyuan.setThread(threads);

        liyuan.start();
//        liyuan.join();
        synchronized (liyuan) {
            liyuan.wait();
        }

        lishiming.start();
        liyuanba.start();

//        lishiming.join();
//        liyuanba.join();

        try {
            for (int i = 0; i < 50; i++) {
                TimeUnit.MILLISECONDS.sleep(10);
                System.out.println(Thread.currentThread().getName()+" i is "+i);
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
